<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<ui:composition 
	template="/template/template-controle.xhtml"
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">
	
	<ui:define name="titulo">Manter participante</ui:define>	
	
	<ui:define name="corpo">
		
		<br/>
		
		<div class="container" style="width:1150px;">
		
			<h:form id="loginForm">
			
				<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
				<script type="text/javascript" src="http://jquery-joshbush.googlecode.com/files/jquery.maskedinput-1.2.1.pack.js"></script>
				<script type="text/javascript" src="#{facesContext.externalContext.requestContextPath}/js/jquery/jquery.maskMoney.js"></script>
				
				<script type="text/javascript">
	
					jQuery(function(){
						jQuery('input[id*="nome"]').focus();
						jQuery('input[id*="telefone"]').mask("(99) 9999-9999");
					});
					
				</script>
				
				<script type="text/javascript">
					
					jQuery(document).ready(function(jQuery){
			               jQuery('input[id*="peso"]').maskMoney({symbol:'Kg ', showSymbol:true, thousands:'.', decimal:',', symbolStay: true}); 
			               jQuery('input[id*="meta"]').maskMoney({symbol:'Kg ', showSymbol:true, thousands:'.', decimal:',', symbolStay: true}); 
			               jQuery('input[id*="quantidadeDoacao"]').maskMoney({symbol:'Kg ', showSymbol:true, thousands:'.', decimal:',', symbolStay: true});
			        });
				
				</script>
			
				<h3 align="left">Manter participante</h3>
				<div align="center" style="position: relative;"> <hr align="center" style=" height: 01px;" class="btn-danger sombra"/></div>
				
				<h6>Os campos que contém o " <span style="color: red; font-size: 15px;">*</span> " são obrigatórios.</h6>
				
				<div class="control-group error">
					<table cellspacing="10" width="700px">
						<tr>
							<td>
								<h4><span style="color: red; font-size: 15px;" >*</span> Nome:</h4>
								<p:inputText 
									id="nome" 
									value="#{manterParticipanteBean.participante.nmParticipante}"
									maxlength="100" 
									style="width:220px;"/>
				            </td>
						</tr>
						<tr>
				            <td>
								<h4>Cidade:</h4>
								<p:inputText  
									id="cidade"
									value="#{manterParticipanteBean.participante.cidade}" 
		                        	maxlength="70" 
		                        	style="width:200px;" />
				            </td>
						</tr>
						<tr>
				            <td>
								<h4><span style="color: red; font-size: 15px;" >*</span> Telefone:</h4>
								<p:inputText  
									id="telefone"
									value="#{manterParticipanteBean.participante.telefone}"
									maxlength="14"
									style="width:150px;">
								</p:inputText>
								
				            </td>
						</tr>
						<tr>
				            <td>
								<h4><span style="color: red; font-size: 15px;" >*</span> Email:</h4>
								<p:inputText  
									id="email" 
									value="#{manterParticipanteBean.participante.email}"
		                        	maxlength="80" 
		                        	style="width:170px;" />
				            </td>
						</tr>
						<tr>
				            <td>
								<h4><span style="color: red; font-size: 15px;" >*</span> Peso atual:</h4>
								<p:inputText  
									id="peso"
									value="#{manterParticipanteBean.participante.peso}" 
		                        	maxlength="9" 
		                        	style="width:70px;" />
				            </td>
						</tr>
						<tr>
				            <td>
								<h4>Meta na balança:</h4>
								<p:inputText  
									id="meta"
									value="#{manterParticipanteBean.participante.meta}" 
		                        	maxlength="9" 
		                        	style="width:70px;" />
				            </td>
						</tr>
						<tr>
				            <td>
								<h4>Estimativa de doação:</h4>
								<p:inputText  
									id="quantidadeDoacao"
									value="#{manterParticipanteBean.participante.quantidadeDoacao}" 
		                        	maxlength="9" 
		                        	style="width:70px;" />
				            </td>
						</tr>
					</table>
				</div>
				
				<br />
				
				<div align="left">
					
					<p:commandButton 
						styleClass="btn btn-danger sombra"
						id="botaoSalvar" 
						value="Cadastrar"
						action="#{manterParticipanteBean.salvarParticipante}" 
						update="msgSistema, loginForm, listaParticipante" 
						ajax="false" 
						style="margin-left:5px;"> 
					</p:commandButton>	
					
					<p:commandButton 
						styleClass="btn btn-danger sombra"
						id="botaoLimpar" 
						value="Limpar"
						action="#{manterParticipanteBean.limparCampos}" 
						update=":msgSistema, :loginForm" 
						ajax="false" 
						style="margin-left:5px;">
					</p:commandButton>
				</div>
				
				<br/>
			
			</h:form>
				
			<h3 align="left">Lista de participante cadastrados</h3>
			<div align="center" style="position: relative;"> <hr align="center" style=" height: 01px;" class="btn-danger sombra"/></div>
			
			<h:form id="listaParticipante" styleClass="sombra">
				
				<p:dataTable 
					id="listaCadastroParticipante" 
					var="participante"
					paginator="true" 
					rows="10" 
					paginatorPosition="bottom"
					value="#{manterParticipanteBean.todosParticipante}"
					emptyMessage="Nenhum participante encontrado">
	
					<p:column 
						sortBy="#{participante.nmParticipante}"
						style="width:400px;"
						filterBy="#{participante.nmParticipante}"
						headerText="Nome" filterMatchMode="contains">
						<h:outputText value="#{participante.nmParticipante}" />
					</p:column>
					
					<p:column 
						sortBy="#{participante.cidade}" 
						filterBy="#{participante.cidade}"
						headerText="Cidade" filterMatchMode="contains">
						<h:outputText value="#{participante.cidade}"/>
					</p:column>
					
					<p:column  
						sortBy="#{participante.telefone}"
						filterBy="#{participante.telefone}"
						headerText="Telefone" filterMatchMode="contains">
						<h:outputText value="#{participante.telefone}" />
					</p:column>
					
					<p:column 
						sortBy="#{participante.email}" 
						style="width:250px;"
						filterBy="#{participante.email}"
						headerText="Email" filterMatchMode="contains">
						<h:outputText value="#{participante.email}" />
					</p:column>
					
					<p:column
						sortBy="#{participante.peso}"
						style="width:50px;"  
						headerText="Peso atual" filterMatchMode="contains">
						<h:outputText value="#{participante.peso}"/>
					</p:column>
					
					<p:column
						sortBy="#{participante.meta}"
						style="width:50px;"  
						headerText="Meta na balança" filterMatchMode="contains">
						<h:outputText value="#{participante.meta}"/>
					</p:column>
					
					<p:column
						sortBy="#{participante.quantidadeDoacao}"
						style="width:50px;"  
						headerText="Estimativa de doação" filterMatchMode="contains">
						<h:outputText value="#{participante.quantidadeDoacao}" />
					</p:column>
	
					<p:column 
						style="width:130px;"
						headerText="Ações">
					
						<p:commandButton 
							update=":loginForm"
							image="ui-icon ui-icon-pencil" 
							immediate="true">
							<f:setPropertyActionListener 
								value="#{participante}"
								target="#{manterParticipanteBean.participante}" />
						</p:commandButton>
					
						<p:commandButton 
							oncomplete="confirmation.show()"
							image="ui-icon ui-icon-trash" 
							immediate="false">
							<f:setPropertyActionListener 
								value="#{participante}"
								target="#{manterParticipanteBean.participanteAux}" />
						</p:commandButton>
					</p:column>
				</p:dataTable>
				
				<p:confirmDialog 
					message="Deseja excluir o registro?"
					widgetVar="confirmation">
					
					<div align="center">
						
						<p:commandButton 
							value="Sim"
							update=":msgSistema, :listaParticipante"
							oncomplete="confirmation.hide()" 
							immediate="true"
							actionListener="#{manterParticipanteBean.exluirParticipante}">
						</p:commandButton>
						
						<p:commandButton 
							value="Não" 
							update=":msgSistema, :listaParticipante"
							onclick="confirmation.hide()"
							immediate="true"
							actionListener="#{manterParticipanteBean.limparCampos}">
						</p:commandButton>
					</div>
				</p:confirmDialog>
			</h:form>
		</div>	
	</ui:define>
</ui:composition>